﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonExtensions.IEnumerableExtensions;
using CommonExtensions.ObjectExtensions;
using CommonExtensions.StringExtensions;

namespace DBMigrator.Core.DbObjects.Data.What
{
    public class AdditionalWhat : BaseWhat, IAdditionalWhat
    {
        public AdditionalWhat(IAdditionalWhat additionalWhat, IWhatColumnList columnList) 
            : base(additionalWhat, columnList)
        {}

        public IAdditionalWhat AndColumn(string columnName)
        {
            return AndColumns(columnName);
        }

        public IAdditionalWhat AndColumns(params string[] columnNames)
        {
            ColumnList.AddColumns(columnNames);
            return AdditionalWhat;
        }

        public IAdditionalWhat AndAllColumnsFrom(string tableName)
        {
            if (tableName.IsBlank())
                throw new ArgumentNullException("tableName");

            ColumnList.AddAllTableColumns(tableName);
            return AdditionalWhat;
        }

        public IAdditionalWhat AndColumnsFrom(string tableName, params string[] columnNames)
        {
            if(tableName.IsBlank())
                throw new ArgumentNullException("tableName");
            if (columnNames.IsNull())
                throw new ArgumentNullException("columnNames");
            if(columnNames.IsEmpty())
                throw new ArgumentOutOfRangeException("columnNames", "columnNames cannot be blank");
            if (columnNames.Any(c => c.IsBlank()))
                throw new ArgumentException("Column names cannot be null or empty", "columnNames");

            ColumnList.AddTableColumns(tableName, columnNames);
            return AdditionalWhat;
        }
    }
}
